package com.gitee.huxing.course.conc.task;

import java.util.concurrent.*;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.conc.task
 * @ClassName: TaskService01Impl
 * @Author: huxing
 * @DateTime: 2021-08-25 下午4:58
 */
public class TaskThreadPool07 extends AbstractTaskThreadPool{

    public static void main(String[] args) throws InterruptedException{
        new TaskThreadPool07().task();
    }

    @Override
    public int threadTask() {
        final int[] result = new int[1];
        CyclicBarrier barrier = new CyclicBarrier(1,
                () -> result[0] = CourseTask.sum());
        // 线程处理
        try {
            barrier.await();
        } catch (Exception ex){
            ex.printStackTrace();
        }
        return result[0];
    }
}
